<template>
  <el-dialog
    :visible.sync="dialogVisible"
    :title="dialogTitle"
    width="35%"
    @close="close"
  >
    <div class="form-box">
      <el-form
        ref="ruleForm"
        :rules="rules"
        :model="dialogForm"
        label-width="120px"
      >
        <el-form-item label="文件夹名称：" prop="folderName">
          <el-input
            v-model="dialogForm.folderName"
            placeholder="请输入文件夹名称"
            autocomplete="false"
          />
        </el-form-item>
      </el-form>
    </div>
    <template #footer>
      <span class="dialog-footer">
        <span class="dialog-footer">
          <el-button type="primary" plain @click="close()">取消</el-button>
          <el-button type="primary" @click="confirmDialog()"> 确定 </el-button>
        </span>
      </span>
    </template>
  </el-dialog>
</template>
<script>
export default {
  name: "dataDictionaryDialog",
  components: {},
  props: {
    curItem: {
      type: Object,
      default: () => {},
    },
    dialogTitle: {
      type: String,
      default: "",
    },
  },
  data: () => {
    return {
      dialogVisible: false,
      rules: {
        folderName: [{ required: true, message: "请输入", trigger: "blur" }],
      },
      dialogForm: {
        folderName: "",
        id: "",
      },
      isEdit: "",
    };
  },
  computed: {},
  created() {},
  methods: {
    show(obj) {
      this.dialogVisible = true;
      this.isEdit = obj.isEdit;
      if (obj.isEdit == 1) {
        this.dialogForm.folderName = this.curItem.dirName;
      }
    },
    close() {
      this.dialogVisible = false;
      this.dialogForm = {
        folderName: "",
        id: "",
      };
    },
    confirmDialog() {
      this.$refs.ruleForm.validate((valid) => {
        if (valid) {
          const params = {
            id: null,
            parentId: 0,
            dirName: this.dialogForm.folderName,
          };
          if (this.isEdit == 1) {
            params.parentId = this.curItem.parentId;
            params.id = this.curItem.id;
          }
          if (this.isEdit == 0) {
            params.parentId = this.curItem.id;
          }
          this.$axios
            .post(this.$api.dataConnection.fileSource.saveFile, params)
            .then((res) => {
              const { code } = res.data || {};
              if (code === 200) {
                this.close();
                this.$emit("initData");
              }
            });
        } else {
          console.log("error submit!!");
          return false;
        }
      });
    },
  },
};
</script>
